package net.javastone.toolkit.core.dataformat;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.BitSet;

/**
 * BitSet Serializer
 */
public class BitSetSerializer extends StdSerializer<BitSet> {

  public BitSetSerializer() {
    super(BitSet.class);
  }

  @Override
  public void serialize(BitSet v, JsonGenerator jgen, SerializerProvider sp) throws IOException {
    long[] longs = v.toLongArray();
    StringBuilder sb = new StringBuilder();
    for (long l : longs) {
      sb.append(l).append('|');
    }
    jgen.writeString(sb.toString());
  }

}

